﻿namespace GoodAdmin.Web.Core;

/// <summary>
/// 角色管理控制器
/// </summary>
[ApiDescriptionSettings("System", Tag = "角色管理")]
[Route("system/role")]
public class RoleController: IDynamicApiController
{
    private readonly ISysRoleService _roleService;
    private readonly IRoleExtraService _roleExtraService;

    public RoleController(ISysRoleService roleService,IRoleExtraService roleExtraService)
	{
        _roleService = roleService;
        _roleExtraService = roleExtraService;
    }
    #region GET
    /// <summary>
    /// 获取角色列表
    /// </summary>
    /// <returns></returns>
    [HttpGet("list")]
    [DisplayName("所有角色列表")]
    public async Task<List<SysRole>> GetRoleList()
    {
        return await _roleService.GetRoleList();
    }
    /// <summary>
    /// 获取角色已授权用户
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("ownUser")]
    [DisplayName("获取角色已授权用户")]
    public async Task<List<UserSimpleInfo>> GetRoleOwnUser([FromQuery] BaseIdInput input)
    {
        return await _roleExtraService.GetRoleOwnUser(input.Id);
    }

    /// <summary>
    /// 获取角色已授权组织
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("ownOrg")]
    [DisplayName("获取角色已授权组织")]
    public async Task<List<long>> GetRoleOwnOrg([FromQuery] BaseIdInput input)
    {
        return await _roleService.GetRoleOwnOrg(input.Id);
    }

    /// <summary>
    /// 获取角色已授权职位
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("ownOrg")]
    [DisplayName("获取角色已授权职位")]
    public async Task<List<long>> GetRoleOwnPosition([FromQuery] BaseIdInput input)
    {
        return await _roleService.GetRoleOwnPosition(input.Id);
    }
    /// <summary>
    /// 分页查询角色列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>

    [HttpGet("page")]
    [DisplayName("分页查询")]
    public async Task<SqlSugarPagedList<SysRole>> GetRolePage([FromQuery] RolePageInput input)
    {
        return await _roleService.GetRolePage(input);
    }

    /// <summary>
    /// 分页查询角色选择器
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpGet("selector")]
    [DisplayName("角色选择")]
    public async Task<List<RoleSelectorOutput>> GetRoleSelector([FromQuery] RolePageInput input)
    {
        return await _roleService.GetRoleSelector(input);
    }

    [HttpGet("ownResource")]
    [DisplayName("获取角色已分配资源")]
    public async Task<RoleResourceInfo> GetRoleOwnResource([FromQuery] BaseIdInput input)
    {
        return await _roleService.GetRoleOwnResource(input);
    }

    [HttpGet("ownMenu")]
    [DisplayName("获取角色已分配菜单")]
    public async Task<List<long>> GetRoleOwnMenu([FromQuery] BaseIdInput input)
    {
        return await _roleService.GetRoleOweMenu(input);
    }
    #endregion

    #region post
    /// <summary>
    /// 新建角色
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("add")]
    [DisplayName("新建角色")]
    public async Task AddRole(RoleAddInput input)
    {
        await _roleService.AddRole(input);
    }

    /// <summary>
    /// 更新角色
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("update")]
    [DisplayName("更新角色")]
    public async Task UpdateRole(RoleUpdateInput input)
    {
        await _roleService.UpdateRole(input);
    }

    /// <summary>
    /// 删除角色
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("delete")]
    [DisplayName("删除角色")]
    public async Task DeleteRole(List<BaseIdInput> input)
    {
        await _roleService.DeleteRole(input);
    }

    
    /// <summary>
    /// 为角色分配菜单
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("grantRoleMenus")]
    [DisplayName("分配菜单")]
    public async Task GrantRoleMenus(RoleMenusInput input)
    {
        await _roleService.GrantRoleMenus(input);
    }

    /// <summary>
    /// 为角色授权用户
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("grantRoleUsers")]
    [DisplayName("授权用户")]
    public async Task GrantRoleUsers(RoleUsersInput input)
    {
        await _roleService.GrantRoleUsers(input);
    }

    /// <summary>
    /// 为角色授权组织
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("grantRoleOrgs")]
    [DisplayName("授权组织")]
    public async Task GrantRoleOrgs(RoleOrgsInput input)
    {
        await _roleService.GrantRoleOrgs(input);
    }

    /// <summary>
    /// 为角色授权职位
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost("grantRolePositions")]
    [DisplayName("授权职位")]
    public async Task GrantRolePositions(RolePositionsInput input)
    {
        await _roleService.GrantRolePositions(input);
    }

    [HttpPost("grantRoleResource")]
    [DisplayName("为角色分配资源")]
    public async Task GrantRoleResource(RoleResourceInput input)
    {
        await _roleService.GrantRoleResource(input);
    }
    #endregion
}
